import pygame, random

# colours
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
PITCH = (0, 128, 0)

class Goal(object):
	"""Handles goal boundaries"""
	
	topleftx = 85
	toplefty = 160
	width = 655
	height = 205

class Pointer(pygame.sprite.Sprite):
	
	def __init__(self):
		
		pygame.sprite.Sprite.__init__(self)
		
		self.width = 10
		self.height = 10
		self.speed = 0.3
		self.speedlimit = 0.3
		self.x = 300.0
		self.y = 200.0
		self.direction = ([10.0, 10.0])
		self.stopped = False
		
		self.image = pygame.Surface([self.width, self.height])
		self.image.fill(RED)
		self.rect = self.image.get_rect()

	def bounce(self, plane):
		if plane == "hor":
			self.direction[1] -= 2*self.direction[1]
		else:
			self.direction[0] -= 2*self.direction[0]
	
	def stopandstart(self):
		if not self.stopped:
			self.direction = ([0.0,0.0])
			self.stopped = True
		else:
			self.reset()
			self.stopped = False
			
	def reset(self):
		self.x = 300.0
		self.y = 200.0
		self.direction = ([10.0, 10.0])
		self.stopped = False
	
	# Functions for testing whether the pointer has moved out of bounds
	def inrangex(self):
		if (self.x < Goal.topleftx) or (self.x > (Goal.topleftx + Goal.width)):
			return False
		else:
			return True
			
	def inrangey(self):
		if (self.y < Goal.toplefty) or (self.y > (Goal.toplefty + Goal.height)):
			return False
		else:
			return True		
			
	def update(self):
		self.x += self.speed * self.direction[0]
		self.y += self.speed * self.direction[1]
		self.rect.left = self.x
		self.rect.top = self.y
		
		if not self.inrangex():
			self.bounce("ver")
		elif not self.inrangey():
			self.bounce("hor")
			
		if random.randint(1,100) == 1:
			self.speed += 0.05
		
		if self.speed > self.speedlimit:
			self.speed = self.speedlimit
	
